package com.esoon.capital.cis.util;

import com.acconsys.cws.CisServer;
import com.acconsys.cws.SOAPClient;
import com.acconsys.cws.SOAPRequest;
import com.acconsys.cws.SOAPResponse;

import java.io.File;

public class CisUtil {

    public static File getProjects() {

        File projectFile =new File("Projects.xml");
        //如果文件已经存在，则直接返回，如果文件不存在，则调接口，界面用户可以点击刷新根节点再次获取节点下的数据。
        if(!projectFile.exists()){
            try {
                CisServer server = new CisServer("127.0.0.1", 49901);
                SOAPRequest request = new SOAPRequest();
                request.setUsername("system");
                request.setPassword("manager");
                request.setPayload("<projects/>");
                request.build(true);
                SOAPClient client = new SOAPClient();
//			System.out.println( server.getProjectsListService().toString());
                SOAPResponse response = client.callService(request, server.getProjectsListService());
                System.out.println(projectFile.getAbsolutePath());
                response.saveBody(projectFile);
                System.out.println(response.getSoapResponse());

            } catch (Exception e) {
                e.printStackTrace();
            }

        }
        return  projectFile;
    }

}
